using System;
using System.Net;
using System.Net.Sockets;
namespace cjx.ProxySocket
{
	public class ProxySocket : Socket
	{
		private object object_0;
		private IPEndPoint ipendPoint_0;
		private ProxyTypes proxyTypes_0;
		private string string_0;
		private string string_1;
		private AsyncCallback asyncCallback_0;
		private Class6 dlkshdWy2;
		private Exception exception_0;
		private int int_0;
		public IPEndPoint ProxyEndPoint
		{
			get
			{
				return this.ipendPoint_0;
			}
			set
			{
				this.ipendPoint_0 = value;
			}
		}
		public ProxyTypes ProxyType
		{
			get
			{
				return this.proxyTypes_0;
			}
			set
			{
				this.proxyTypes_0 = value;
			}
		}
		public string ProxyUser
		{
			get
			{
				return this.string_0;
			}
			set
			{
				if (value == null)
				{
					throw new ArgumentNullException();
				}
				this.string_0 = value;
			}
		}
		public string ProxyPass
		{
			get
			{
				return this.string_1;
			}
			set
			{
				if (value == null)
				{
					throw new ArgumentNullException();
				}
				this.string_1 = value;
			}
		}
		public ProxySocket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType) : this(addressFamily, socketType, protocolType, "")
		{
		}
		public ProxySocket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType, string proxyUsername) : this(addressFamily, socketType, protocolType, proxyUsername, "")
		{
		}
		public ProxySocket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType, string proxyUsername, string proxyPassword) : base(addressFamily, socketType, protocolType)
		{
			this.ProxyUser = proxyUsername;
			this.ProxyPass = proxyPassword;
			this.method_9(new InvalidOperationException());
		}
		public new void Connect(EndPoint remoteEP)
		{
			if (remoteEP == null)
			{
				throw new ArgumentNullException("<remoteEP> cannot be null.");
			}
			if (base.ProtocolType != ProtocolType.Tcp || this.ProxyType == ProxyTypes.None || this.ProxyEndPoint == null)
			{
				base.Connect(remoteEP);
				return;
			}
			base.Connect(this.ProxyEndPoint);
			if (this.ProxyType == ProxyTypes.Socks4)
			{
				new Class5(this, this.ProxyUser).vmethod_1((IPEndPoint)remoteEP);
				return;
			}
			if (this.ProxyType == ProxyTypes.Socks5)
			{
				new Class4(this, this.ProxyUser, this.ProxyPass).vmethod_1((IPEndPoint)remoteEP);
			}
		}
		public new void Connect(string host, int port)
		{
			if (host == null)
			{
				throw new ArgumentNullException("<host> cannot be null.");
			}
			if (port <= 0 || port > 65535)
			{
				throw new ArgumentException("Invalid port.");
			}
			if (base.ProtocolType != ProtocolType.Tcp || this.ProxyType == ProxyTypes.None || this.ProxyEndPoint == null)
			{
				base.Connect(new IPEndPoint(Dns.Resolve(host).AddressList[0], port));
				return;
			}
			base.Connect(this.ProxyEndPoint);
			if (this.ProxyType == ProxyTypes.Socks4)
			{
				new Class5(this, this.ProxyUser).vmethod_0(host, port);
				return;
			}
			if (this.ProxyType == ProxyTypes.Socks5)
			{
				new Class4(this, this.ProxyUser, this.ProxyPass).vmethod_0(host, port);
			}
		}
		public new IAsyncResult BeginConnect(EndPoint remoteEP, AsyncCallback callback, object state)
		{
			if (remoteEP == null || callback == null)
			{
				throw new ArgumentNullException();
			}
			if (base.ProtocolType != ProtocolType.Tcp || this.ProxyType == ProxyTypes.None || this.ProxyEndPoint == null)
			{
				return base.BeginConnect(remoteEP, callback, state);
			}
			this.asyncCallback_0 = callback;
			if (this.ProxyType == ProxyTypes.Socks4)
			{
				this.method_7(new Class5(this, this.ProxyUser).vmethod_2((IPEndPoint)remoteEP, new Delegate0(this.method_3), this.ProxyEndPoint));
				return this.method_6();
			}
			if (this.ProxyType == ProxyTypes.Socks5)
			{
				this.method_7(new Class4(this, this.ProxyUser, this.ProxyPass).vmethod_2((IPEndPoint)remoteEP, new Delegate0(this.method_3), this.ProxyEndPoint));
				return this.method_6();
			}
			return null;
		}
		public new IAsyncResult BeginConnect(string host, int port, AsyncCallback callback, object state)
		{
			if (host == null || callback == null)
			{
				throw new ArgumentNullException();
			}
			if (port <= 0 || port > 65535)
			{
				throw new ArgumentException();
			}
			this.asyncCallback_0 = callback;
			if (base.ProtocolType != ProtocolType.Tcp || this.ProxyType == ProxyTypes.None || this.ProxyEndPoint == null)
			{
				this.method_11(port);
				this.method_7(this.method_0(host, new Delegate0(this.method_3)));
				return this.method_6();
			}
			if (this.ProxyType == ProxyTypes.Socks4)
			{
				this.method_7(new Class5(this, this.ProxyUser).vmethod_3(host, port, new Delegate0(this.method_3), this.ProxyEndPoint));
				return this.method_6();
			}
			if (this.ProxyType == ProxyTypes.Socks5)
			{
				this.method_7(new Class4(this, this.ProxyUser, this.ProxyPass).vmethod_3(host, port, new Delegate0(this.method_3), this.ProxyEndPoint));
				return this.method_6();
			}
			return null;
		}
		public new void EndConnect(IAsyncResult asyncResult)
		{
			if (asyncResult == null)
			{
				throw new ArgumentNullException();
			}
			if (!asyncResult.IsCompleted)
			{
				throw new ArgumentException();
			}
			if (this.method_8() != null)
			{
				throw this.method_8();
			}
		}
		internal Class6 method_0(string string_2, Delegate0 delegate0_0)
		{
			Class6 result;
			try
			{
				Dns.BeginResolve(string_2, new AsyncCallback(this.method_1), this);
				result = new Class6();
			}
			catch
			{
				throw new SocketException();
			}
			return result;
		}
		private void method_1(IAsyncResult iasyncResult_0)
		{
			try
			{
				IPHostEntry iPHostEntry = Dns.EndResolve(iasyncResult_0);
				base.BeginConnect(new IPEndPoint(iPHostEntry.AddressList[0], this.method_10()), new AsyncCallback(this.method_2), this.method_4());
			}
			catch (Exception exception_)
			{
				this.method_3(exception_);
			}
		}
		private void method_2(IAsyncResult iasyncResult_0)
		{
			try
			{
				base.EndConnect(iasyncResult_0);
				this.method_3(null);
			}
			catch (Exception exception_)
			{
				this.method_3(exception_);
			}
		}
		private void method_3(Exception exception_1)
		{
			if (exception_1 != null)
			{
				base.Close();
			}
			this.method_9(exception_1);
			this.method_6().method_1();
			if (this.asyncCallback_0 != null)
			{
				this.asyncCallback_0(this.method_6());
			}
		}
		private object method_4()
		{
			return this.object_0;
		}
		private void method_5(object value)
		{
			this.object_0 = value;
		}
		private Class6 method_6()
		{
			return this.dlkshdWy2;
		}
		private void method_7(Class6 value)
		{
			this.dlkshdWy2 = value;
		}
		private Exception method_8()
		{
			return this.exception_0;
		}
		private void method_9(Exception value)
		{
			this.exception_0 = value;
		}
		private int method_10()
		{
			return this.int_0;
		}
		private void method_11(int value)
		{
			this.int_0 = value;
		}
	}
}
